package com.example.vote.mapper;

import com.example.vote.entity.TpItems;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 投票系统-题目选项表-9 Mapper 接口
 * </p>
 *
 * @author 廖老师
 * @since 2023-12-04
 */
public interface TpItemsMapper extends BaseMapper<TpItems> {

    @Select("select * from tp_items where vid=#{vid}")
    @Results({
            @Result(column = "id", property = "id", id = true),
            @Result(column = "id", property = "recordCnt",
                one = @One(select = "selectRecordCnt"))
    })
    List<TpItems> selectByVid(int vid);

    @Select("select count(*) from tp_record where iid = #{iid}")
    int selectRecordCnt(int iid);

}
